<template>
  <view class="c-b">
    <view class="cart-container" v-if="cart.length!==0">
      <!-- 我的地址 -->
      <my-addres></my-addres>
      <!-- 商品标题 -->
      <view class="top-text">
        <uni-icons type="shop" size="16"></uni-icons>
        <text>购物车</text>
      </view>
      <!-- 循环数据 -->


      <uni-swipe-action>
        <block v-for="(item,i) in cart" :key="i">

          <uni-swipe-action-item :right-options="options" @click="removeItem(item)">
            <my-goods :showNum="true" :showRadio="true" :item="item" @addCart="addCart"
              @numChangeHandler="numChangeHandler"></my-goods>
          </uni-swipe-action-item>

        </block>

      </uni-swipe-action>
      <my-settlement></my-settlement>
    </view>
    <view class="white" v-else>
      <image src="@/static/1.png" mode=""></image>
      <text>什么都没有~~~</text>
    </view>
  </view>

</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'

  export default {
    mixins: [badgeMix],
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#dd524d'
          }
        }]
      };
    },
    onShow() {},
    methods: {
      ...mapMutations('m_cart', ['clickR', 'addCount', 'removeGoods']),
      addCart(e) {
        this.clickR(e)
      },
      numChangeHandler(e) {
        this.addCount(e)
      },
      removeItem(item) {
        this.removeGoods(item)
      }
    }
  }
</script>

<style lang="scss">
  .cart-container {
    padding-bottom: 50px;
  }

  .top-text {
    display: flex;
    padding: 8px 0;
    padding-left: 5px;
    border-bottom: 1px solid #fff;

    text {
      font-size: 14px;
      margin-left: 5px;
    }
  }
  .white {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-top: 150px;
    image {
      width: 90px;
      height: 90px;
      margin-bottom: 20px;
    }
  }
</style>
